package com.carlos.company.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

/**
 * 用户
 * @author Carlos Li
 * @date 2021/3/5
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@TableName("sys_user")
public class SysUser implements UserDetails {

    private static final long serialVersionUID = 7192579864793509721L;

    @TableId(type = IdType.INPUT)
    private String username;
    @JsonIgnore
    private String password;

    @JsonIgnore
    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    public SysUser(String username, String password) {
        this.username = username;
        this.password = password;
    }

}